#!/usr/bin/env python
#coding:utf-8
# author : wangwei
# mail   ：alsww@qq.com
# oldboy s10 python training

import sys
import time

def shoppingList(n,m):
    goods_dict={}
    goods = open('goods_list.txt','r+')
    for line in goods.readlines():
        key = line.split()[0]
        value = line.split()[1]+' '+line.split()[2]
        goods_dict[key] = value
    print "现在的用户是： %s." %n
    #打印商品列表
    for k,v in goods_dict.items():
        print "%s:%s"%(k,v)
    #选择商品
    choice_num = int(raw_input("请选序号：").strip())
    goods_name = goods_dict[`choice_num`].split()[0]
    goods_value = int(goods_dict[`choice_num`].split()[1])
    m = calc(int(m),goods_value)
    #记入日志
    shoppingInfo(n,goods_name,goods_value,0)
    return m

#计算剩余的钱
def calc(money,price):
    shengyu_money = money - price
    return shengyu_money
#记入购物日志函数
def shoppingInfo(user,name,price,shouxufei):
    transfer_time=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
    p = "record_list.txt"
    f = open(p,'a')
    f.write("%s|%s|%s|%d|%d  \n"  %(user,transfer_time,name,price,shouxufei))
    f.close()